<!--
* @Author       : 李江涛
* @Description  : 
-->

<template>
  <div class="p-4">
    <h1>欢迎来到home页<trophy-two-tone /></h1>
    <h3>我的名字叫：{{ userStore.name }} <el-button type="primary" @click="updateName('李四')">点击我使用pinia更名为李四</el-button></h3>
    <RouterLink to="/login">点击我去登录页</RouterLink>
  </div>
</template>
<script lang="ts">
export default {name: 'Home'};
</script>

<script lang="ts" setup>
import {onMounted} from 'vue';
import {useUserStore} from '@/store/user';
import {testGet} from '@/axios/api/user';
import {RequestManager} from '@/axios/concurrencyLimiter';

const userStore = useUserStore();

onMounted(async () => {
  console.log('[ 欢迎来到首页 ] ==>');
  const requestManager = new RequestManager(2);

  requestManager.addRequest(testGet).then(() => {
    console.log('[ 1 ] ==>');
  });
  requestManager.addRequest(testGet).then(() => {
    console.log('[ 2 ] ==>');
  });
  requestManager.addRequest(testGet).then(() => {
    console.log('[ 3 ] ==>');
  });
  requestManager.addRequest(testGet).then(() => {
    console.log('[ 4 ] ==>');
  });
});

const updateName = (name: string) => {
  userStore.updateName(name);
};
</script>

<style lang="scss" scoped></style>
